//import org.apache.http.HttpEntity;
//import org.apache.http.HttpHost;
//import org.apache.http.HttpResponse;
//import org.apache.http.client.config.RequestConfig;
//import org.apache.http.client.methods.*;
//import org.apache.http.config.Registry;
//import org.apache.http.config.RegistryBuilder;
//import org.apache.http.conn.socket.ConnectionSocketFactory;
//import org.apache.http.conn.socket.PlainConnectionSocketFactory;
//import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
//import org.apache.http.impl.client.CloseableHttpClient;
//import org.apache.http.impl.client.HttpClients;
//import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
//import org.apache.http.util.EntityUtils;
//
//import javax.net.ssl.SSLContext;
//import javax.net.ssl.TrustManager;
//import javax.net.ssl.X509TrustManager;
//import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStreamReader;
//import java.net.URL;
//import java.net.URLConnection;
//import java.nio.charset.StandardCharsets;
//import java.security.KeyManagementException;
//import java.security.NoSuchAlgorithmException;
//import java.util.HashMap;
//import java.util.Map;
//
//public class HttpClientTest {
//    static String  url = "http://api.beisenapp.com:80/RecruitV2/600493/applicant/GetApplicantIdsByDateAndStatus";
//    static String param = "start_time=20210601000000&end_time=20210610000000&job_id=&status_id=S017&phase_id=U02";
//    static String accessToken = "Bearer 9c6bc3a4bf6b44d28d466c3988f9188c";
//
//    public void beiSenDemo() {
//        // 通过Get请求从北森获取数据
//        String result = "";
//        BufferedReader in = null;
//        try {
//            String urlNameString = url + "?" + param;
//            URL realUrl = new URL(urlNameString);
//            URLConnection connection = realUrl.openConnection();
//            connection.addRequestProperty("Authorization", accessToken);
//            connection.setRequestProperty("accept", "*/*");
//            connection.setRequestProperty("connection", "Keep-Alive");
//            connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
//            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
//            connection.connect();
//            in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
//            String line;
//            while ((line = in.readLine()) != null) {
//                result += line;
//            }
//        } catch (Exception e) {
//            System.out.println("发送GET请求出现异常！" + e);
//            e.printStackTrace();
//        } finally {
//            try {
//                if (in != null) {
//                    in.close();
//                }
//            } catch (Exception e2) {
//                e2.printStackTrace();
//            }
//        }
//        System.out.println("BeiSenDemo : " + result);
//    }
//
//
//
//    public static void main(String[] args) {
////        HttpClientTest beiSenApiTest = new HttpClientTest();
////
////      //  beiSenApiTest.beiSenDemo();
////
////        String header = "Authorization:" + accessToken +
////                "\n accept:*/*" +
////                "\n connection:Keep-Alive"+
////                "\n User-Agent:Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"+
////                "\n Content-Type:application/x-www-form-urlencoded";
////
////        beiSenApiTest.httpReq(url + "?" + param, header);
//        Map<String, String> map = new HashMap<>();
//        map.put("a", null);
//
//        System.out.println(map.get("a"));
//       // System.out.println(map.get("a").getClass().getName());
//
//        System.out.println(String.valueOf(map.get("a")));
//
//    }
//
//
//
//        public static void  httpReq(String url, String header)  {
//            Map<String, Object> headerMap = new HashMap<>();
//            if(header != "" && header != null) {
//                for (String  par : header.replace("\\r", "").split("\\n")) {
//                    int pos = par.indexOf(":");
//                    if (pos > -1){
//                        //Content-Type  User-Agent  Referer
//                        String name = par.substring(0, pos);
//                        String value = par.substring(pos + 1).trim();
//                        if("content-type".equals(name.toLowerCase())){
//                            headerMap.put("Content-Type", value);
//                        }else if("user-agent".equals(name.toLowerCase())){
//                            headerMap.put("User-Agent", value);
//                        }else if("referer".equals(name.toLowerCase())){
//                            headerMap.put("Referer", value);
//                        }else{
//                            headerMap.put(name, value);
//                        }
//                    }
//                }
//            }
//
//            byte [] data = null;
//            try{
//                data = httpRequest(url, "GET", headerMap);
//            }catch (Exception e){
//               e.printStackTrace();
//            }
//
//            String result =  new String(data, StandardCharsets.UTF_8);
//
//            System.out.println("httpReq : " + result);
//
//        }
//
//        private static byte [] httpRequest(String url, String method, Map<String, Object> headerMap) throws NoSuchAlgorithmException, KeyManagementException {
//            CloseableHttpClient httpClient;
//            if(url.toUpperCase().startsWith("HTTPS")){
//                httpClient = getHttpClient("TLS"); //SSLv3
//            }else{
//                httpClient = HttpClients.createDefault();
//            }
//
//            HttpRequestBase httpRequest = null;
//            String m = method.toUpperCase();
//            switch (m){
//                case "GET":
//                    httpRequest =   new HttpGet(url);
//                    break;
//                case "POST":
//                    httpRequest =   new HttpPost(url);
//                    break;
//                case "PUT":
//                    httpRequest =   new HttpPut(url);
//                    break;
//                case "DELETE":
//                    httpRequest =   new HttpDelete(url);
//                    break;
//                default:
//                    throw new RuntimeException("HttpMethod Not Support " + m );
//            }
//
//
//            HttpHost proxy=new HttpHost("172.19.231.18", 9999,"http");
//            RequestConfig  config =  RequestConfig.custom().setProxy(proxy).build();
//            httpRequest.setConfig(config);
//            if(headerMap != null) {
//                for (Map.Entry<String, Object> e : headerMap.entrySet()) {
//                    httpRequest.setHeader(e.getKey(), e.getValue() != null ? e.getValue().toString() : "");
//                }
//            }
//            HttpResponse response = null;
//            byte [] data = null;
//            try{
//                response = httpClient.execute(httpRequest);
//                int statucCode = response.getStatusLine().getStatusCode();
//                if(statucCode == 200) {
//                    HttpEntity entity = response.getEntity();
//                    data = EntityUtils.toByteArray(entity);
//                }else {
//                    System.out.println("ERROR :" + (buildErrMsg(url, "GET", headerMap.toString(), "", statucCode)));
//                }
//            }catch (Exception e) {
//                e.printStackTrace();
//                System.out.println("ERROR :" + (buildErrMsg(url, "GET", headerMap.toString(), "", 0) + "\n" +e));
//            }
//            finally {
//                try {
//                    httpClient.close();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//            return data;
//        }
//
//        private static String buildErrMsg(String url, String method, String header, String data, int statueCode) {
//            StringBuffer sb = new StringBuffer();
//            sb.append("接口调用失败： StatuCode：" + statueCode + " ; ");
//            sb.append("URL：" + url + " ; ");
//            sb.append("METHOD：" + method + " ; ");
//            sb.append("HEADER：" + header + " ; ");
//            if("POST".equals(method.toUpperCase())) {
//                sb.append("POSTDATA：" + data+ " ; ");
//            }
//            return sb.toString();
//        }
//
//
//        /**
//         * 绕过验证
//         *
//         * @return
//         * @throws NoSuchAlgorithmException
//         * @throws KeyManagementException
//         */
//        public static SSLContext createIgnoreVerifySSL(String algorithm) throws NoSuchAlgorithmException, KeyManagementException {
//            SSLContext sc = SSLContext.getInstance(algorithm);// SSLv3
//
//            // 实现一个X509TrustManager接口，用于绕过验证，不用修改里面的方法
//            X509TrustManager trustManager = new X509TrustManager() {
//                @Override
//                public void checkClientTrusted(
//                        java.security.cert.X509Certificate[] paramArrayOfX509Certificate,
//                        String paramString) {
//                }
//
//                @Override
//                public void checkServerTrusted(
//                        java.security.cert.X509Certificate[] paramArrayOfX509Certificate,
//                        String paramString) {
//                }
//
//                @Override
//                public java.security.cert.X509Certificate[] getAcceptedIssuers() {
//                    return null;
//                }
//            };
//
//            sc.init(null, new TrustManager[] { trustManager }, null);
//            return sc;
//        }
//
//
//
//        private static CloseableHttpClient getHttpClient(String algorithm) throws KeyManagementException, NoSuchAlgorithmException {
//            SSLContext sslcontext = createIgnoreVerifySSL(algorithm);
//
//            // 设置协议http和https对应的处理socket链接工厂的对象
//            Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
//                    .register("http", PlainConnectionSocketFactory.INSTANCE)
//                    .register("https", new SSLConnectionSocketFactory(sslcontext))
//                    .build();
//            PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
//            HttpClients.custom().setConnectionManager(connManager);
//
//            //创建自定义的httpclient对象
//            return HttpClients.custom().setConnectionManager(connManager).build();
//        }
//
//
//
//}
